package ua.kpi_java_training.zabrodskyi.module3;

/**
 * The class describes a cell in environment.
 * 
 * @author Maksym Zabrodskyi
 * @version 24-Jun-2013
 */
public class Cell {

	/**
	 * Coordinates x and y at a cell.
	 */
	private int x;
	private int y;

	/**
	 * Cell creation with coordinates by default if coordinates aren't
	 * specified.
	 */
	public Cell() {
		this.x = 0;
		this.y = 0;
	}

	/**
	 * Cell creation with certain coordinates x, y.
	 */
	public Cell(int x, int y) {
		this.x = x;
		this.y = y;
	}

	/**
	 * Cell creation from other cell. Coordinates of a new cell will be same, as
	 * well as a cell from which it was created.
	 */
	public Cell(Cell cell) {
		this(cell.x, cell.y);
	}

	/**
	 * Set up of coordinates of this cell from other cell.
	 * 
	 * @param cell
	 *            - any cell in environment.
	 */
	public void setCell(Cell cell) {
		this.x = cell.getX();
		this.y = cell.getY();
	}

	/**
	 * Returns the coordinate x of cell.
	 * 
	 * @return x of cell.
	 */
	public int getX() {
		return x;
	}

	/**
	 * Set up new coordinate x for a cell.
	 * 
	 * @param x
	 *            - integer number.
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * Returns the coordinate y of cell.
	 * 
	 * @return y of cell.
	 */
	public int getY() {
		return y;
	}

	/**
	 * Set up the new coordinate y for a cell.
	 * 
	 * @param y
	 *            - integer number.
	 */
	public void setY(int y) {
		this.y = y;
	}

	/**
	 * Checks the cell is correct - whether there is a cell within the
	 * environment sizes.
	 * 
	 * @return true if cell is correct, false otherwise.
	 */
	public boolean isBad() {
		return getX() < 0 || getX() >= Settings.getWidth() || getY() < 0
				|| getY() >= Settings.getHeight();
	}

	/**
	 * Compares cells on flatness. Two cells are considered equal if their
	 * coordinates x and y are equal.
	 * 
	 * @param object
	 *            - any cell.
	 */
	@Override
	public boolean equals(Object object) {
		Cell cell = (Cell) object;
		return cell.x == x && cell.y == y;
	}

	/**
	 * Converts an instance of this class in a string.
	 */
	@Override
	public String toString() {
		return String.format("[%s,%s]", this.x, this.y);
	}

}
